﻿/*
 *
 * This stored procedure deletes ALL the data in the Zen4Sync database.
 * If @param_DeleteReferenceData is set to 1 (i.e. "true") the reference data is also deleted.
 * If the parameter isn't provided, it defaults to 0 (i.e. "false") and the reference data is not deleted.
 *
 */
CREATE PROCEDURE [Admin].[sp_z4s_purge_database]
	@param_DeleteReferenceData BIT = 0
AS
	DELETE FROM [MEF].[mefExecutionHistory]
	DELETE FROM [SQLCEBackup].[sqlceBackupHistory]
	DELETE FROM [SQLCEExecution].[sqlceExecutionHistory]
	DELETE FROM [SQLServerExecution].[sqlServerExecutionHistory]
	DELETE FROM [Scenario].[activityContext]
	DELETE FROM [Scenario].[activityHistory]
	DELETE FROM [Admin].[clientSession]
	DELETE FROM [MEF].[mefDeployment]
	DELETE FROM [Admin].[testServer]
	DELETE FROM [Admin].[testSession]
	DELETE FROM [Admin].[testSessionCategory]
	DELETE FROM [MEF].[mefExecution]
	DELETE FROM [MEF].[mefComponentVersion]
	DELETE FROM [MEF].[mefComponent]
	DELETE FROM [MEF].[mefExecutionContext]	
	DELETE FROM [MergeSync].[syncSession]
	DELETE FROM [MergeSync].[distributor]
	DELETE FROM [MergeSync].[internet]
	DELETE FROM [MergeSync].[publisher]
	DELETE FROM [MergeSync].[syncSessionContext]
    DELETE FROM [MergeSync].[subscriber]	
	DELETE FROM [Scenario].[activity]
	DELETE FROM [Scenario].[testScenario]
	DELETE FROM [SQLCEBackup].[sqlceBackup]
	DELETE FROM [SQLCEBackup].[sqlceBackupContext]	
	DELETE FROM [SQLCEExecution].[sqlceCheckData]
	DELETE FROM [SQLCEExecution].[sqlceCheckDataParameter]
	DELETE FROM [SQLCEExecution].[sqlceCheckDataContext]
	DELETE FROM [SQLCEExecution].[sqlceExecution]
	DELETE FROM [SQLCEExecution].[sqlceExecutionParameter]
	DELETE FROM [SQLCEExecution].[sqlceExecutionContext]	
	DELETE FROM [SQLServerExecution].[sqlServerCheckData]
	DELETE FROM [SQLServerExecution].[sqlServerCheckDataParameter]	
	DELETE FROM [SQLServerExecution].[sqlServerCheckDataContext]
	DELETE FROM [SQLServerExecution].[sqlServerExecution]
	DELETE FROM [SQLServerExecution].[sqlServerExecutionParameter]
	DELETE FROM [SQLServerExecution].[sqlServerExecutionContext]	

	IF @param_DeleteReferenceData = 1
	BEGIN
		DELETE FROM [Admin].[sqlValueType]
		DELETE FROM [Admin].[testSessionState]
		DELETE FROM [MergeSync].[exchangeType]
		DELETE FROM [MergeSync].[networkType]
		DELETE FROM [MergeSync].[securityType]
		DELETE FROM [MergeSync].[snapshotTransferType]
		DELETE FROM [MergeSync].[validateType]
		DELETE FROM [Scenario].[activityType]
	END
RETURN 0